<template>
    <div>
      <el-dialog
        title="添加采购"
        :visible.sync="dialogAddCartVisible"
        width="30%">

        <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">

        <el-form-item
          label="采购数量"
          prop="num"
          :rules="[{ required: true, message: '采购数量不能为空'}, { type: 'number', message: '采购数量必须为数字值'}]"
        >
          <el-input type="num" v-model.number="form.num" autocomplete="off"></el-input>
        </el-form-item>


          <el-form-item>
            <el-button type="primary" @click="_addToCart('form')">添加</el-button>
            <el-button @click="dialogAddCartVisible = false">关闭</el-button>
          </el-form-item>

        </el-form>





      </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "GoodsProductAddCart",

      data(){
          return{
            dialogAddCartVisible:false,
            form:{
              num:'',
              productId:''
            },



          }
      },
      methods:{
        _open(id){
          this.form.num='';
          this.form.productId=id;
          this.dialogAddCartVisible=true;
        },

        _addToCart(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {

              this.$http.post("/t_purchase_cart/add_to_cart", {productId:this.form.productId,num:this.form.num}).then(result=>{
                console.log("result:"+result)

                this.dialogAddCartVisible=false;

              }).catch(err=>{
                console.log(err);
              })


            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },



      },
    }
</script>

<style scoped>

</style>
